`
https://leetcode.cn/problems/max-consecutive-ones-iii/
`

/**
 * @param {number[]} nums
 * @param {number} k
 * @return {number}
 */
var longestOnes = function (nums, k) {
  let left = 0, right = 0;

  let res = 0

  while (right < nums.length) {
    if (nums[right] === 0) {
      k--
    }
    right++

    while (k < 0) {
      if (nums[left] === 0) {
        k++
      }
      left++
    }

    res = Math.max(res, right - left)
  }

  return res
};